package com.app.micaihu.view.army.adapter

import android.widget.ImageView
import com.app.micaihu.R
import com.app.micaihu.view.bean.ArmyDetail
import com.app.micaihu.view.bean.ArmyIcon
import com.app.micaihu.view.utils.loadImage
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * 军团头像 适配器
 */
class ArmyHeadListAdapter : BaseQuickAdapter<ArmyIcon, BaseViewHolder>(R.layout.army_head_list_item) {

    override fun convert(holder: BaseViewHolder, item: ArmyIcon) {
        holder.apply {
            getView<ImageView>(R.id.ivHeadPic).loadImage(item.icon)
            if (item.select) {
                setImageResource(R.id.ivSelect, R.mipmap.army_member_select_on)
            } else {
                setImageResource(R.id.ivSelect, R.mipmap.army_member_select_off)
            }
        }

    }

    fun setSelect(position: Int) {
        val item = getItem(position)
        for (it in data) {
            it.select = it.icon == item.icon
        }
        notifyDataSetChanged()
    }

    fun getSelect(): String {
        var selectIcon = ""
        for (it in data) {
            if (it.select) {
                selectIcon = it.icon
                break
            }
        }
        return selectIcon
    }
}